import { request } from '../../../api/request.js'
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    radioValue: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  radioOneChange(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    console.log(obj)
    this.setData({
      'list[0]': obj
    })
  },
  radioTwoChange(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)

    this.setData({
      'list[1]': obj
    })
  },
  radioThreeChange(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    this.setData({
      'list[2]': obj
    })

  },
  radioFourChange(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    this.setData({
      'list[3]': obj
    })
  },
  radioFiveChange(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    this.setData({
      'list[4]': obj
    })

  },
  radioSixChange(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    this.setData({
      'list[5]': obj
    })
  },
  questionSeven(e) {
    console.log(e)
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    console.log(obj)
    this.setData({
      'list[6]': obj
    })
  },
  questioneight1(e) {
    this.setData({
      'radioValue[0]': e.detail.value
    })

  },
  questioneight2(e) {
    this.setData({
      'radioValue[1]': e.detail.value
    })

  },
  questioneight3(e) {
    this.setData({
      'radioValue[2]': e.detail.value
    })

  },
  questioneight4(e) {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options.push(e.detail.value)
    this.setData({
      'list[8]': obj
    })

  },
  submit() {
    let obj = {
      options: [],
      title: "  ",
      type: 0
    }
    obj.options = this.data.radioValue
    this.setData({
      'list[7]': obj
    })

    console.log(this.data.list)
    let arr = { list: [] }
    arr.list = this.data.list
    request({
      url: "/questionnaire/addQuestionnaire",
      data: arr
    }).then(res => {
      console.log(res)
      if (res.code !== 0) {
        return Toast.fail("提交失败,请填写问题内容");
      }
      Toast.success("提交成功,谢谢反馈")
      let time = setTimeout(() => {
        wx.navigateBack({
          delta: -1,
          success: (res => {
            if (res.errMsg == "navigateBack:ok") {
              clearTimeout(time)
            }
          })
        })
      }, 2000)
    }).catch(() => {
      Toast.fail("提交失败,请填写问题内容");
    })
  }
})